Skip to content

perf(compiler): bypass dynamic dispatch for known-array appends - #97

Merged
matyhtf merged 1 commit into
swoole:masterfrom
yavon007:codex/investigate-array-append
Sep 8, 2026
Merged

perf(compiler): bypass dynamic dispatch for known-array appends#97
matyhtf merged 1 commit into
swoole:masterfrom
yavon007:codex/investigate-array-append

Conversation

@yavon007

@yavon007 yavon007 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

For known arrays, append expressions such as $items[] = makeValue() still use offsetSet(null, tmp) when the RHS needs materialization or the assignment result is used. That dispatches through runtime type/key checks before reaching Array::append.

Call append(tmp) directly for Type::ARRAY, retaining the existing RHS temporary and expression result. Dynamic receivers, simple statement fast paths, and explicit reference assignments retain their existing lowering.

Adds a code-generation regression test, an executable semantics test covering references, assignment results, copy-on-write and RHS mutation, and a standalone append benchmark with raw measurements and reproduction instructions.

Performance

On Linux ARM64 in Docker, PHP 8.5.10 ZTS, PHPX 6a68f38, GCC -O2 without LTO, against baseline 692841a6: 100 million appends took a median 980.88 ms before and 563.60 ms after (42.54% less elapsed time). All nine alternating measured pairs were faster after one discarded warm-up pair; checksums matched. This is an append-heavy microbenchmark on a shared development machine, not an application-wide speedup or a claim about native PHP performance.

Validation

  • HotPathCodegenTest: 5 tests, 25 assertions pass; new codegen test fails against the original trait.
  • Three targeted PHPTs pass: array-append-expression, array-statement-write-optimized, and array-value-write-dereferences-source.
  • Baseline and candidate semantics outputs match PHP 8.5.10; native PHP benchmark checksum matches both compiled binaries.
  • git diff --check passes. Full-suite and cross-platform validation were not run.

@matyhtf
matyhtf merged commit d1136cf into swoole:master Sep 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants